package com.example.easyexcel.service.impl;

import com.alibaba.excel.EasyExcel;
import com.example.easyexcel.dao.AssetReportInfoMapper;
import com.example.easyexcel.dto.AssetReportInfo;
import com.example.easyexcel.listener.AssetReportInfoListener;
import com.example.easyexcel.service.AssetReportInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

@Service
@RequiredArgsConstructor
@Slf4j
public class AssetReportInfoServiceImpl implements AssetReportInfoService {

    private final AssetReportInfoMapper assetReportInfoMapper;

    @Override
    public void importReportExcel(MultipartFile file) {
        //单条插入或批量插入
        try (InputStream inputStream = file.getInputStream()) {
            EasyExcel.read(inputStream, AssetReportInfo.class, new AssetReportInfoListener(assetReportInfoMapper))
                    .sheet()
                    .doRead();
        } catch (Exception e) {
            throw new RuntimeException("Report_Excel 导入失败", e);
        }
    }
}
